/*     */ package blockbuster.utils.texture;
/*     */ 
/*     */ import java.io.IOException;
/*     */ import java.nio.ByteBuffer;
/*     */ import java.util.ArrayList;
/*     */ import java.util.List;
/*     */ import net.minecraft.client.Minecraft;
/*     */ import net.minecraft.client.renderer.GlStateManager;
/*     */ import net.minecraft.client.renderer.texture.AbstractTexture;
/*     */ import net.minecraft.client.renderer.texture.ITextureObject;
/*     */ import net.minecraft.client.renderer.texture.ITickableTextureObject;
/*     */ import net.minecraft.client.renderer.texture.TextureManager;
/*     */ import net.minecraft.client.resources.IResourceManager;
/*     */ import net.minecraft.util.ResourceLocation;
/*     */ import net.minecraftforge.fml.relauncher.Side;
/*     */ import net.minecraftforge.fml.relauncher.SideOnly;
/*     */ import org.lwjgl.opengl.GL11;
/*     */ 
/*     */ @SideOnly(Side.CLIENT)
/*     */ public class GifTexture
/*     */   extends AbstractTexture
/*     */   implements ITickableTextureObject {
/*     */   public static int globalTick;
/*     */   public ResourceLocation texture;
/*  25 */   public List<GifElement> elements = new ArrayList<>();
/*     */ 
/*     */ 
/*     */   
/*     */   public int index;
/*     */ 
/*     */   
/*     */   public int duration;
/*     */ 
/*     */   
/*     */   public int width;
/*     */ 
/*     */   
/*     */   public int height;
/*     */ 
/*     */ 
/*     */   
/*     */   public static void bindTexture(ResourceLocation location, int ticks, float partialTicks) {
/*  43 */     TextureManager textures = (Minecraft.func_71410_x()).field_71446_o;
/*     */     
/*  45 */     if (location.func_110623_a().endsWith("gif")) {
/*  46 */       ITextureObject object = textures.func_110581_b(location);
/*     */       
/*  48 */       if (object instanceof GifTexture) {
/*  49 */         GifTexture texture = (GifTexture)object;
/*  50 */         int lastIndex = texture.index;
/*     */         
/*  52 */         if (ticks >= 0) {
/*  53 */           texture.calculateIndex(ticks, partialTicks);
/*     */         }
/*     */         
/*  56 */         GlStateManager.func_179144_i(texture.func_110552_b());
/*     */         
/*  58 */         if (ticks >= 0) {
/*  59 */           texture.index = lastIndex;
/*     */         }
/*     */         
/*     */         return;
/*     */       } 
/*     */     } 
/*     */     
/*  66 */     textures.func_110577_a(location);
/*     */   }
/*     */   
/*     */   public static void updateTick() {
/*  70 */     globalTick++;
/*     */   }
/*     */   
/*     */   public GifTexture(ResourceLocation texture) {
/*  74 */     this.texture = texture;
/*     */   }
/*     */   
/*     */   public void add(int delay, ByteBuffer buffer) {
/*  78 */     this.elements.add(new GifElement(delay, this.width, this.height, buffer));
/*     */   }
/*     */   
/*     */   public void calculateDuration() {
/*  82 */     this.duration = 0;
/*     */     
/*  84 */     for (GifElement element : this.elements) {
/*  85 */       this.duration += element.delay;
/*     */     }
/*     */   }
/*     */ 
/*     */ 
/*     */   
/*     */   public void func_110551_a(IResourceManager resourceManager) throws IOException {}
/*     */ 
/*     */   
/*     */   public void func_110550_d() {
/*  95 */     Minecraft mc = Minecraft.func_71410_x();
/*     */ 
/*     */     
/*  98 */     if (mc.field_71439_g == null) {
/*     */       return;
/*     */     }
/*     */     
/* 102 */     calculateIndex(globalTick, 0.0F);
/*     */   }
/*     */   
/*     */   public void calculateIndex(int ticks, float partial) {
/* 106 */     int tick = (int)((ticks + partial) * 20.0F % this.duration);
/*     */     
/* 108 */     int duration = 0;
/* 109 */     int index = 0;
/*     */     
/* 111 */     this.index = 0;
/*     */     
/* 113 */     for (GifElement element : this.elements) {
/* 114 */       duration += element.delay;
/*     */       
/* 116 */       if (tick < duration) {
/* 117 */         this.index = index;
/*     */         
/*     */         break;
/*     */       } 
/* 121 */       index++;
/*     */     } 
/*     */   }
/*     */ 
/*     */   
/*     */   public int func_110552_b() {
/* 127 */     if (this.index < 0 || this.index >= this.elements.size()) {
/* 128 */       return -1;
/*     */     }
/*     */     
/* 131 */     return ((GifElement)this.elements.get(this.index)).id;
/*     */   }
/*     */ 
/*     */   
/*     */   public void func_147631_c() {
/* 136 */     for (GifElement element : this.elements) {
/* 137 */       GL11.glDeleteTextures(element.id);
/* 138 */       element.id = -1;
/*     */     } 
/*     */   }
/*     */   
/*     */   public static class GifElement {
/*     */     public int delay;
/*     */     public int id;
/*     */     
/*     */     public GifElement(int delay, int w, int h, ByteBuffer buffer) {
/* 147 */       this.delay = delay;
/* 148 */       this.id = GL11.glGenTextures();
/*     */       
/* 150 */       GL11.glBindTexture(3553, this.id);
/* 151 */       GL11.glTexParameteri(3553, 10241, 9728);
/* 152 */       GL11.glTexParameteri(3553, 10240, 9728);
/*     */       
/* 154 */       GL11.glTexImage2D(3553, 0, 32856, w, h, 0, 6408, 5121, buffer);
/*     */     }
/*     */   }
/*     */ }


/* Location:              D:\fanbian\[D][龙之核心]DragonCore-2.6.0.3.jar!\blockbuste\\utils\texture\GifTexture.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */